package com.zcn.io.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zcn.io.common.pojo.CommonResult;
import com.zcn.io.web.api.entity.AnswerRecordTask;
import com.zcn.io.web.api.query.AnswerRecordTaskQuery;
import com.zcn.io.web.api.vo.AnswerRecordTaskDtlOrderVo;
import com.zcn.io.web.service.AnswerRecordTaskService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @desc:
 * @author: 202438 邱建伟
 * @date: 2024/11/3 17:48
 * @Copyright (c) 2024, 江苏金恒信息科技股份有限公司
 */

@RestController
@AllArgsConstructor
    @RequestMapping("/answerRecordTask")
public class AnswerRecordTaskController {

    private final AnswerRecordTaskService answerRecordTaskService;

    @GetMapping("/list")
    public CommonResult<Page<AnswerRecordTask>> list(Page<AnswerRecordTask> page, AnswerRecordTask orderMain) {
        answerRecordTaskService.list(page, orderMain);
        return CommonResult.success(page);
    }

    @PostMapping("/save")
    public CommonResult<String> save(@RequestBody AnswerRecordTask orderMain) {
        answerRecordTaskService.save(orderMain);
        return CommonResult.success("新增成功");
    }

    @PostMapping("/updateById")
    public CommonResult<String> updateById(@RequestBody AnswerRecordTask orderMain) {
        answerRecordTaskService.updateById(orderMain);
        return CommonResult.success("修改成功");
    }

    /**
     * @desc: 执行一次指定时间内电话接听记录统计结果
     * @author 202438 邱建伟
     * @date 2024/11/3 16:00
     */
    @PreAuthorize("hasAuthority('super_man')")
    @PostMapping("/startAnswerRecordTask")
    public CommonResult<String> startAnswerRecordTask(@RequestBody AnswerRecordTaskQuery query) {
        return CommonResult.success(answerRecordTaskService.startAnswerRecord(query));
    }

    @GetMapping("/listByTaskId")
    public CommonResult<Page<AnswerRecordTaskDtlOrderVo>> listByTaskId(Page<AnswerRecordTaskDtlOrderVo> page, AnswerRecordTaskQuery query) {
        answerRecordTaskService.listByTaskId(page, query);
        return CommonResult.success(page);
    }

    @PreAuthorize("hasAuthority('super_man')")
    @DeleteMapping("/deleteById")
    public CommonResult<String> deleteById(String id) {
        answerRecordTaskService.deleteById(id);
        return CommonResult.success("删除成功!");
    }
}
